package com.example.springboot.mapper;
import com.example.springboot.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where username=#{username}")
     User findByUserName(String username);
    @Insert("insert into user(username, password, user_phone, idCard,update_time,create_time,role) " +
            "values(#{username}, #{password}, #{userphone}, #{idCard},now(),now(),'USER')")
    void register(String username, String password, String userphone, String idCard);

    @Update("update user set nick_name=#{nickname}, user_phone=#{userphone},user_photo=#{userphoto},sex=#{sex},update_time=now(),user_address=#{useraddress} where id=#{id}")
    void update(User user);

    @Insert("insert into user(username, password, nick_name, user_phone,user_photo,sex,user_address,idCard,create_time,update_time,role) " +
            "values(#{username}, #{password},#{nickname},#{userphone},#{userphoto},#{sex},#{useraddress},#{idCard},now(),now(),'USER')")
    void add(User user);
    //查找全部
    @Select("select * from user where role='USER'")
    List<User> findAll();
    //删除
    @Select("delete from user where id=#{id}")
    void delete(Integer id);


}
